"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const comment_1 = require("../model/comment");
function default_1(app) {
    app.post("/api/addcomment", function (req, res) {
        return __awaiter(this, void 0, void 0, function* () {
            let comments = req.body;
            const { success, data } = yield (0, comment_1.addComment)(comments);
            if (success) {
                res.json({ success: true, msg: "添加成功" });
                return;
            }
            else {
                res.json({ success: true, msg: "添加失败" });
                return;
            }
        });
    });
    app.post("/api/getcomment", function (req, res) {
        return __awaiter(this, void 0, void 0, function* () {
            let { page, blog_id } = req.body;
            const { success, data } = yield (0, comment_1.readComments)(Number(page), blog_id);
            console.log(data, success);
            if (success) {
                const result = yield (0, comment_1.getTotal)(blog_id);
                if (success) {
                    res.json({ success: true, data: data, total: result.data[0].total });
                    return;
                }
            }
            else {
                res.json({ success: false, data: "获取失败" });
                return;
            }
        });
    });
}
exports.default = default_1;
